package com.example.service.Impl;

import com.example.mapper.BlogMapper;
import com.example.mapper.UserInfoMapper;
import com.example.model.BlogInfo;
import com.example.model.UserInfo;
import com.example.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * User: 阿宾
 * Date: 2025-05-14
 * Time: 19:10
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogMapper blogMapper;
    @Override
    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    @Override
    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    @Override
    public UserInfo getAuthorInfo(Integer blogId) {
        //1.根据博客ID，获取作者ID
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        log.info("blogInfo:{}",blogInfo);
        //2.根据作者ID，获取作者信息
        if(blogInfo == null || blogInfo.getUserId() <= 0){
            log.error("博客不存在，blogId：{}",blogId);
            return null;
        }
        return userInfoMapper.selectById(blogInfo.getUserId());
    }
}
